﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;

namespace CFScript.PInvoke
{
    class Runtime
    {
        const int MAX_PATH = 1024;
        public static string GetCallingExe()
        {
            string result = "N/A";

            byte[] buffer = new byte[MAX_PATH * 2];

            int chars = GetModuleFileName(IntPtr.Zero, buffer, MAX_PATH);

            if (chars > 0)
            {
                result = System.Text.Encoding.Unicode.GetString(buffer, 0, chars * 2);
            }

            return result;
        }
        

        [DllImport("coredll.dll", SetLastError = true)]
        private static extern int GetModuleFileName(IntPtr hModule, byte[] lpFilename, int nSize);
    }
}
